//author:kakake
/**
 * 以下两个接口以应用发布服务的方式提供给支付系统应用调用
 */
class tspaynotifyController {
    public data = {
        dbConn: TSLobsterAPI.Program.GetDbConn(),
        WorkId: 1
    }

    public service: tspaynotifyService;
    public dao: tspaynotifyDao;
    public tsregisterservice: tsregisterService;
    public tsselfpayservice: tsselfpayService;

    constructor() {
        this.data.WorkId = TSLobsterAPI.Program.GetWorkId();

        this.service = new tspaynotifyService(this.data.WorkId);
        this.dao = new tspaynotifyDao(this.data.WorkId);
        this.tsregisterservice = new tsregisterService(this.data.WorkId);
        this.tsselfpayservice = new tsselfpayService(this.data.WorkId);
    }

    /**
     * 支付成功回调此函数
     * 参数：
        let body = JSON.parse(TSLobsterAPI.Program.RequestBody());
        let backpayobj = {
            OrderType: body.OrderType,                  //1挂号支付 2处方支付
            OrderNo: body.OrderNo || '',                //支付系统生成的订单号
            TransactionId: body.TransactionId || '',    //微信支付生成的唯一号
            BusinessOrderNo: body.BusinessOrderNo || 0, //业务号，对应WPMT_RegisteredPayment和WPMT_PresPayment表的主键
            SubMchId: body.SubMchId,                    //商户号
            PayType: body.payType,                      //支付方式 1微信 2医保 3其它
            PayDate: body.PayDate,                      //支付时间
            PayFee: parseFloat(body.PayFee) / 100       //支付金额 到分
        }
     */
    paysuccess() {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        if (model.OrderType == 1) {
            //挂号费支付成功
            this.tsregisterservice.registerpaysuccess(model);
        }
        else if (model.OrderType == 2) {
            //处方支付成功
            this.tsselfpayservice.balancepaysuccess(model);
        }
        return { result: true };
    }

    /**
     * 退款成功回调此函数
        let body = JSON.parse(TSLobsterAPI.Program.RequestBody());
        let backrefundobj = {
            OrderType: body.OrderType,                              //1挂号支付 2处方支付
            OrderNo: body.OrderNo || '',                            //支付系统生成的订单号
            TransactionId: body.TransactionId || '',                //微信支付生成的唯一号
            BusinessOrderNo: body.BusinessOrderNo || 0,             //业务号，对应WPMT_RegisteredPayment和WPMT_PresPayment表的主键
            RefundNo:body.RefundNo || '',                           //退款订单号
            RefundTransactionId:body.RefundTransactionId || '',     //退款交易流水号
            SubMchId: body.SubMchId,                                //商户号
            PayType: body.payType,                                  //支付方式 1微信 2医保 3其它
            RefundDate: body.RefundDate,                            //支付时间
            RefundFee: parseFloat(body.RefundFee) / 100             //支付金额 到分
        }
     */
    refundsuccess() {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        if (model.OrderType == 1) {
            //退挂号费成功
            this.tsregisterservice.cancelregisterrefundsuccess(model);
        }
        else if (model.OrderType == 2) {
            //处方退费成功

        }
        return { result: true };
    }
}